home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / pctecap.arc / MEMINIT.ASM < prev    next >
Assembly Source File  |  1986-03-15  |  9KB  |  252 lines

  1. page 60,132
  2. title 'MEMINIT - Obtain all available user memory'
  3. subttl 'Version 1.0 October, 1983'
  4.  
  5. stack SEGMENT para stack 'STACK'
  6.       db 16 dup('stack   ')
  7. stack ENDS
  8.  
  9. data SEGMENT at 40H           ; DOS data segment in low memory
  10.          org 13H
  11.          memory_size dw       ; total memory size (K bytes)
  12.          io_ram_size dw       ; memory in I/O channel (K bytes)
  13. data ENDS
  14.  
  15. code SEGMENT byte
  16.  
  17.          assume cs:code,ds:code,ss:stack
  18.  
  19.          original_memory_size  dw ?     ;
  20.          original_io_memory    dw ?     ; all sizes stored in 'K' bytes
  21.          additional_memory     dw ?     ;
  22.          starting_memory_block dw ?     ; location of program's PSP
  23.          command_proc_PSP      dw ?     ; location of command's PSP
  24.                                         ; (PSP=program segment prefix)
  25.  
  26.          crlf      db 10,13,'$'
  27.          msg1      db 'Original memory used:'
  28.          msg1data  db '       K bytes$'
  29.          msg2      db '  Total memory added:'
  30.          msg2data  db '       K bytes$'
  31.          msg3      db '        Total memory:'
  32.          msg3data  db '       K bytes$'
  33.  
  34.  
  35.          heading    db 10,13,'MEMINIT - Version 1.00',10,13
  36.                     db 10,13,'$'
  37.  
  38. .RADIX 16
  39.          dosfunction MACRO function_number
  40.              mov  ah,function_number
  41.              int  21
  42.          endm
  43.  
  44.          print MACRO msg, msgdata
  45.              mov  bx,offset msgdata
  46.              call convert_to_ascii
  47.              mov  dx,offset msg
  48.              dosfunction 9
  49.              mov  dx,offset crlf
  50.              dosfunction 9
  51.          endm
  52.  
  53.  
  54.   convert_to_ascii PROC far
  55.  ;-------------------------
  56.  
  57.                  ; convert_to_ascii converts a binary number
  58.                  ; in AX to ascii display characters
  59.  
  60.          push  dx            ; save register values
  61.          push  si
  62.          mov   cx,6          ; initialize destination with spaces
  63.  
  64.    fill_buff:
  65.          mov  byte ptr [bx],' '
  66.          inc  bx
  67.          loop fill_buff
  68.          mov  si,0A
  69.  
  70.    do_divide:
  71.          sub  dx,dx
  72.          div  si                       ; divide AX by 10
  73.          add  dx,'0'                   ; convert remainder to ASCII digit
  74.          dec  bx
  75.          mov  [bx],dl                  ; store this char in the string
  76.          inc  cs                       ; count converted character
  77.          or   ax,ax                    ; all done?
  78.          jnz  do_divide                ;   no: get next digit
  79.  
  80.          pop  si                       ; Restore registers
  81.          pop  dx
  82.          ret                           ; and exit
  83.  
  84.   convert_to_ascii ENDP
  85.  
  86.  
  87.   update_memory_control_words PROC far
  88.  ;-------------------------------------
  89.  
  90.          assume cs:code,ds:data,ss:stack
  91.  
  92.          push es
  93.          push ds
  94.          mov  ax,data                  ; Set up DS to reference DOS
  95.          mov  ds,ax                    ;    variables in low memory
  96.          mov  ax,starting_memory_block
  97.          dec  ax                       ; AX points to memory control block
  98.                                        ;    starting at that spot, look for
  99.                                        ;    the end of the memory links
  100.                                        ;    ( byte zero = 'Z' )
  101.   find_ending_link:
  102.  
  103.          mov  es,ax                    ; set up address of mem control blk
  104.          cmp  byte ptr es:[0],5AH      ; Is this the ending link?
  105.          jz   found_the_link
  106.          add  ax,es:[3]                ; link to next area
  107.          inc  ax
  108.          jmp  find_ending_link
  109.  
  110.  
  111.   found_the_link:                      ; now update length field of this
  112.                                        ; last mem control block to 
  113.                                        ; include the additional memory
  114.          mov  bx,memory_size
  115.          mov  cl,6
  116.          shl  bx,cl                    ; convert to K bytes
  117.          sub  bx,ax
  118.          dec  bx
  119.          mov  es:[3],bx
  120.  
  121.          pop  ds                       ; restore registers
  122.          pop  es
  123.          clc                           ; indicate normal return (no error)
  124.          ret
  125.  
  126.   update_memory_control_words ENDP
  127.  
  128.  
  129.   memory_size_initialize PROC far
  130.  ;-------------------------------
  131.  
  132.       assume ds:code,cs:code,es:data,ss:stack
  133.  
  134.          mov  cs:starting_memory_block,ds
  135.          push ds
  136.          sub  ax,ax
  137.          push ax
  138.          mov  ax,code
  139.          mov  ds,ax
  140.          mov  dx,es:[0C]               ; COMMAND's program segment prefix
  141.          mov  command_proc_PSP,dx      ;   which we will use to fix up
  142.                                        ;   DOS release 1.1
  143.  
  144.  
  145.          mov  dx,offset heading        ; put out introductory heading
  146.          dosfunction 9
  147.  
  148.  
  149.          mov  bx,data                  ; get ROM-initialized
  150.          mov  es,bx                    ;    memory size
  151.          mov  ax,memory_size           ;    specifications
  152.          mov  original_memory_size,ax
  153.          mov  bx,io_ram_size
  154.          mov  original_io_memory,bx
  155.          mov  cl,6
  156.          shl  ax,cl                    ; convert from K bytes
  157.          mov  bx,0
  158.  
  159.   memory_loop:
  160.  
  161.          cmp  ax,0a000                 ; check if greater than
  162.          je   initialize_memory        ;    640K ..if so then end
  163.          mov  ds,ax
  164.          mov  [bx],ax                  ; write segment # into byte
  165.          mov  cx,[bx]                  ; read segment # from byte
  166.          cmp  ax,cx                    ; if equal..memory exists
  167.          jne  initialize_memory        ;    else no more user memory
  168.          mov  ax,ds
  169.          add  ax,400                   ;  increment segment # by 16K
  170.          jmp  memory_loop              ;    and try some more
  171.  
  172.   initialize_memory:                   ; write data into memory so that
  173.                                        ;  parity errors do no occur upon
  174.                                        ;  access of new memory
  175.  
  176.          mov  bx,memory_size
  177.          mov  cl,6
  178.          shl  bx,cl
  179.  
  180.          push ax                       ; save the value for AX containing
  181.          pop  dx                       ; the new top of memory.
  182.          mov  ax,0                     ;
  183.          cld                           ; set direction=forward
  184.  
  185.   store_initial_value:
  186.  
  187.          cmp  bx,dx
  188.          je   end_of_user_memory       ; go through newly allocated mem
  189.          mov  es,bx                    ; and write a pattern of X'0000'
  190.          mov  cx,03fff                 ; into each word.   This will protect
  191.          mov  di,0                     ; against a fatal parity error later 
  192.          rep  stosw                    ; when mem is read without being 
  193.          add  bx,400                   ; written. (Done 16K bytes at a time.)
  194.          jmp  store_initial_value
  195.  
  196.   end_of_user_memory:
  197.  
  198.          push dx                       ; restore the value for AX
  199.          pop  ax
  200.  
  201.          mov  cl,6                     ;  convert from bytes to
  202.          shr  ax,cl                    ;    K bytes
  203.          mov  bx,code                  ;  calculate changed memory
  204.          mov  ds,bx                    ;    sizes and ..
  205.          mov  bx,data
  206.          mov  es,bx
  207.          mov  memory_size,ax           ;    store back ..
  208.          sub  ax,original_memory_size  ;    into DOS variables
  209.          mov  additional_memory,ax
  210.          add  ax,original_io_memory
  211.          mov  io_ram_size,ax
  212.  
  213.  
  214.          dosfunction 30                ; check DOS version
  215.          cmp  al,00
  216.          je   modify_DOS1              ;  pre 2.0 DOS...handle special
  217.  
  218.          call update_memory_control_words        ;  routine for DOS 2.0
  219.  
  220.          jmp  display_results
  221.  
  222.   modify_DOS1:
  223.  
  224.          push ds
  225.          mov  dx,command_proc_PSP      ; get ready to store new
  226.          mov  ds,dx                    ; memory size in COMMAND's
  227.          mov  dx,memory_size           ; stored variable.
  228.          mov  cl,6
  229.          shl  dx,cl
  230.          mov  ds:[452],dx              ; location of memory size on
  231.          pop  ds                       ;  DOS release 1.1
  232.  
  233.   display_results:
  234.  
  235.          mov  ax,original_memory_size
  236.          print  msg1,msg1data
  237.  
  238.          mov  ax,additional_memory
  239.          print msg2,msg2data
  240.  
  241.          mov  ax,memory_size
  242.          print msg3,msg3data
  243.  
  244.    exit:
  245.          ret
  246.  
  247.   memory_size_initialize ENDP
  248.  
  249. code ENDS
  250.  
  251. END memory_size_initialize
  252.